// pages/biz/InformationList/InformationList.js
import info from './informationServer';
import cf from "../../../utils/config2"
var regeneratorRuntime = require("../../../lib/js/runtime-module.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {

    list: [{
        id: '1',
        name: '美的花湾城地铁站旁贷省级学位内部转让单位',
        time: '2018.10.01  08:50',
        imageUrl: 'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
      },
      {
        id: '1',
        name: '美的置业与时间赛跑 又一场“及时雨”缓解贫困村旱情',
        time: '2018.10.01  08:50',
        imageUrl: 'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
      },
      {
        id: '1',
        name: '美的清风花园国庆购房优惠',
        time: '2018.10.01  08:50',
        imageUrl: 'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
      },
    ],
    businessId:''
  },

  /**
   * 跳转到详情
   */
  goDetail: function(e) {
    let index = e.currentTarget.dataset.index
    let channel = this.data.infoList[e.currentTarget.dataset.index].channel
    console.log(channel,'-------------------channel----------------------------')
    if (channel==1){
      wx.navigateTo({
        url: `/subPackages/pages/InformationDetail/InformationDetail?id=${this.data.infoList[index].contentId}`
      })
    } else if (channel==3){
      wx.navigateTo({
        url: `/subPackages/pages/InformationDetail/InformationDetail?contentId=${this.data.infoList[index].contentId}&productId=${this.data.businessId}`
      })
    }
  },
  getNews(mobile){
    let that = this
    wx.request({
      url:`${cf.dataCenter}zmzj/news/${mobile}/1/9999`,
      header: {
        'content-type': 'application/json',
        'token': wx.getStorageSync('authName')
      },
      success:function(res){
        that.setData({
          infoList:res.data.data?res.data.data.list:[]
        })
      }
    })
  },
  /**
   * 获取列表
   */
  async getList(params) {
    let dataList = await info.getInfoList(params)
    let infoList = dataList.rows
    this.setData({
      infoList

    })
    console.log(dataList, 'dataList')
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let productId = options.productId
    let {mobile,pageType} = options
    this.setData({
      businessId: productId
    })
    let params = {
      businessId: productId,
      // channel:'1'
    }
    if(pageType&&pageType=='card'){
      this.getNews(mobile)
    } else {
      this.getList(params)
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})